<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="css/eui.css">
    <style>
        body {
            margin: 0;
            /*background-image: url("../imgs/fangzhi.jpg");*/
            background-size: cover; /*cover是专门用来设置背景全屏的样式*/
        }

        #app {
            text-align: center;
        }

        h1 {
            font-size: 72px;
            color: rgb(0, 150, 215);
            margin-bottom: 0;
        }

        img {
            width: 100px;
        }

        h2 {
            font-size: 32px;
            color: #0095d7;
            margin: 0;
        }

    </style>
</head>
<body>
<div id="app">
    <h1>欢迎来到管理系统</h1>
    <!--    <img src="../imgs/fangzhi.jpg" alt="">-->
    <h2>Welcome to Zunyi City</h2>
    <el-card style="width: 600px;height: 300px;margin: 0 auto;
  background-color: rgba(255,255,255,0.3)">
        <el-form style="width: 400px;margin: 30px auto" label-width="60px">
            <el-form-item label="用户名">
                <el-input type="text" v-model="user.username"
                          placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input type="password" v-model="user.password"
                          placeholder="请输入密码"></el-input>
            </el-form-item>

            <el-form-item label="类型">
                <template>
                    <el-select v-model="value" placeholder="请选择" style="width: 340px">
                        <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </template>
            </el-form-item>
            <el-form-item v-show="value=='选项1'">
                <el-button type="primary" @click="login(v.value)">登录</el-button>
            </el-form-item>

            <el-form-item v-show="value=='选项2'">
                <el-button type="primary" @click="login(v.value)">登录</el-button>
            </el-form-item>


        </el-form>
    </el-card>
</div>
</body>
<script src="js/vue.min.js"></script>
<!-- import JavaScript -->
<script src="js/eui.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                user: {
                    username: "",
                    password: "",
                    roles_id:""
                },
                options: [{
                    value: '选项1',
                    label: '管理员'
                }, {
                    value: '选项2',
                    label: '用户'
                }],
                value: '选项1',
            }
        },
        created: function () {

        },
        methods: {
            login() {
                if (v.value=='选项1'){
                    v.user.roles_id=1
                }else {
                    v.user.roles_id=2
                }
                axios.post("/user/selectByUsername",v.user).then(function (response){
                    if (response.data == 1) {
                        if (v.value=='选项1'){
                            location.href="/adminIndex.html"
                        }else {
                            location.href="/userIndex.html"
                        }
                    } else if (response.data == 2) {
                        v.$message({
                            message: '密码错误',
                            type: 'warning'
                        });
                    } else if (response.data == 3) {
                        v.$message({
                            message: '没有权限',
                            type: 'warning'
                        });
                    } else {
                        v.$message.error('用户不存在');
                    }
                })
            }
        }
    })
</script>
</html>